package com.gxa.ehome.proxy;

import com.gxa.ehome.pojo.SysUser;
import com.gxa.ehome.service.SysUserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;
@Component("invocationHandler")
public class SysUserServiceInvocaHandler implements InvocationHandler {
     //通过jdk动态代理实现日志自动记录
    //企业中对于日志类型的要求：业务日志，操作日志，错误日志
    @Resource
    private SysUserService sysUserService=null;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("执行的方法"+method.getName()+"传递的参数"+ Arrays.toString(args));
        Object invoke = method.invoke(this.sysUserService,args);
        System.out.println(invoke);
        return invoke;


    }


    /*public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
      //操作前的记录：执行的方法：methdName，传递的参数是：[1,2,3]
        System.out.println("执行的方法"+method.getName()+"传递的参数"+ Arrays.toString(args));
       //method.invoke(sysUserService,args);
               //操作后的记录
        System.out.println(sysUserService);
        SysUserService invoke = (SysUserService)method.invoke(sysUserService,args);

        System.out.println(invoke);
        System.out.println("方法执行成功，返回的结果是");
        return invoke;
    }*/
}
